package com.chaoyong.higo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.ImageView;
import android.widget.TextView;

import com.chaoyong.higo.R;
import com.chaoyong.higo.base.BaseActivity;
import com.chaoyong.higo.bean.ShowOrderEntity;
import com.chaoyong.higo.utils.DataTimeTools;
import com.chaoyong.higo.utils.V;
import com.chaoyong.higo.utils.Values;
import com.chaoyong.higo.view.TitleView;
import com.nostra13.universalimageloader.core.ImageLoader;

public class SharDetailActivity extends BaseActivity {
	
	private ShowOrderEntity entity;
	
	private Context context;
	private TitleView shardet_titleview;
	
	private ImageView headImage;
	private TextView userName;
	private TextView counts;
	private TextView goodsName;
	private TextView shaiName;
	private TextView shaiTime;
	private WebView webView1;
	
	@Override
	public int layoutResID() {
		return R.layout.activity_shar_detail;
	}
	
	@Override
	public void findView() {
		shardet_titleview=V.f(this, R.id.shardet_titleview);
		
		headImage=V.f(this, R.id.headImage);
		userName=V.f(this, R.id.userName);
		counts=V.f(this, R.id.counts);
		goodsName=V.f(this, R.id.goodsName);
		shaiName=V.f(this, R.id.shaiName);
		shaiTime=V.f(this, R.id.shaiTime);
		webView1=V.f(this, R.id.webView1);
	}

	@Override
	public void init() {
		context=this;
		shardet_titleview.setTitleText("晒单详情", context.getResources().getColor(R.color.home_text));
		shardet_titleview.setTitleBack(context.getResources().getColor(R.color.white));
		shardet_titleview.setLeftImage(R.drawable.back_red);
		shardet_titleview.setonLeftClinck(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		entity = (ShowOrderEntity) getIntent().getSerializableExtra("sharEntity");
		setDatas(entity);
	}
	
	private void setDatas(ShowOrderEntity entity2) {
		if (null != entity2) {
			String uri = entity2.getUid_portrait();
			ImageLoader.getInstance().displayImage(Values.BASE_IMAGE_URL + uri, headImage);
			
			String uName = entity2.getUser_name();
			userName.setText(uName);
			
			String c = entity2.getRecord();
			counts.setText(c + "");
			
			String gn = entity2.getGoods_name();
			goodsName.setText(gn + "");
			String sn = entity2.getShare_title();
			shaiName.setText(sn + "");
			
			String st = entity2.getShare_time();
			shaiTime.setText(DataTimeTools.time2(st) + "");
			
			String gi = entity2.getShare_info();
			
			
			WebSettings webSettings = webView1.getSettings();
			webSettings.setSavePassword(false);
			webSettings.setSaveFormData(false);
			webSettings.setDefaultTextEncodingName("UTF-8");
			webSettings.setSupportZoom(true);
			webSettings.setJavaScriptEnabled(true);
			webSettings.setDefaultFontSize(14);
			webSettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); // 图片大小
			
			String web="<!DOCTYPE html><html><head>"
					+ "<meta name="+"\""+"viewport"+"\"content="+"\""+"width=device-width"+"\""+"/>"
							+ "<title>嗨购夺宝</title>"
							+ "<style>"
							+ "img{"
							+ "max-width:95%;"
							+ "width:95%;"
							+ "height:100%;"
							+ "}"
							+ "</style>"
									+ "</head><body>";
			String wei="</body></html>";
			web+=gi;
			web+=wei;
			webView1.loadDataWithBaseURL(null,web
					.replace("&lt;", "<").replace("&gt;", "/>")
					.replace("&amp;", "&"), "text/html","UTF-8", null);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			

		default:
			break;
		}
	}
	
	public void gotoComments(View view){
		Intent intent = new Intent(context, CommentsActivity.class);
		intent.putExtra("key", entity.getId());
		startActivity(intent);
	}
	
}
